import json


from cross_chain_data.code_new.get_cross_chain_event import get_cross_chain_multichain_event
from cross_chain_data.code_new.get_cctx_xulie_eth_bsc import get_cctx_xulie_event_multichain_source,get_cctx_xulie_event_multichain_target

f=open('../data_new/total_data_raw_multichain.json','r')
content=f.read()
f.close()
total_data=json.loads(content)

print(type(total_data))

print(len(total_data))

#抽取交易序列数据
# 遍历总的数据
print("******************交易序列数据开始抽取******************")
# 使用字典进行动态的选择调用的函数

# 抽取的序列数据
data_xulie_cctx=[]
for data_cctx_dict in total_data:
    # 设置单条字典数据
        data_xulie={}
    # 获取源链目标链的名字
    # source_chain_name = data_cctx_dict["cross_chain_data"]["input"]["chain"]
    # target_chain_name = data_cctx_dict["cross_chain_data"]["output"]["chain"]

    # if source_chain_name in chain_function_xulie_source and target_chain_name in chain_function_xulie_source:
    # if source_chain_name in ["ETH","BSC","LTC","BTC","DOGE","AVAX","BCH"] and target_chain_name in ["ETH","BSC","LTC","BTC","DOGE","AVAX","BCH"]:
        # 1.抽取源链事件
        Lock_event,Deposit_event=get_cctx_xulie_event_multichain_source(data_cctx_dict)
        # 2.抽取跨链平台事件
        Lock_action, Unlock_action=get_cross_chain_multichain_event(data_cctx_dict)
        # 3.抽取目标链事件
        Unlock_event=get_cctx_xulie_event_multichain_target(data_cctx_dict)

        # 4.添加数据到空字典中，并打标签
        data_xulie["Lock_event"]=Lock_event
        data_xulie["Deposit_event"]=Deposit_event
        data_xulie["Lock_action"]=Lock_action
        data_xulie["Unlock_action"]=Unlock_action
        data_xulie["Unlock_event"]=Unlock_event
        data_xulie["Type"]="1"

        data_xulie_cctx.append(data_xulie)

# 将最终的数据写入文件中
print(f"全部数据抽取完成，最终总共{len(data_xulie_cctx)}条数据")
json_data=json.dumps(data_xulie_cctx,indent=4)
with open('../data_new/total_data_xulie_multichain.json', 'w', encoding='utf-8') as f:
    f.write(json_data)